//
//  vechileDetailViewController.m
//  WHB_cargo
//
//  Created by 徐国庆 on 15/12/11.
//  Copyright (c) 2015年 turing. All rights reserved.
//

#import "vechileDetailViewController.h"
#import "vechileDetailCell.h"
#import "CWStarRateView.h"

@interface vechileDetailViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong)UITableView *tableView;

@end

@implementation vechileDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navtitle.text = @"货车详情";
    [self initWithVeiw];
}

#pragma mark UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString * indentifer = @"vechileDetailCell";
    NSLog(@"kUIScreenWidth == %f", kUIScreenWidth);
    vechileDetailCell *cell = (vechileDetailCell *)[tableView dequeueReusableCellWithIdentifier:indentifer];
    if (!cell)
    {
        cell=[[NSBundle mainBundle] loadNibNamed:@"vechileDetailCell" owner:self options:nil][0];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    // "车号"
    [cell.vechileNumberView addSubview:[self titleAndContent:@"车号:" andContent:@"京A55563" withToAddress:nil]];
    // “所属公司”
    [cell.belongBusinessView addSubview:[self titleAndContent:@"所属公司:" andContent:@"B集团" withToAddress:nil]];
    // "认证"是否
    cell.identificationImageView.image = [UIImage imageNamed:@"yrz"];
    // “服务评价”
    [cell.serveEvaluateView addSubview:[self fiveCellView:@"服务评价:" withStar:2]];
    // “服务次数”
    [cell.serveCountView addSubview:[self titleAndContent:@"服务次数:" andContent:@"1次" withToAddress:nil]];
    // “介质”
    [cell.mediumView addSubview:[self titleAndContent:@"介质:" andContent:@"汽油" withToAddress:nil]];
    // “重量”
    [cell.weightView addSubview:[self titleAndContent:@"重量:" andContent:@"1吨" withToAddress:nil]];
    // “企业报价”
    [cell.businessPriceView addSubview:[self titleAndContent:@"企业报价:" andContent:@"30000元" withToAddress:nil]];
    // “当前位置”
    [cell.currentAddressVeiw addSubview:[self titleAndContent:@"当前位置:" andContent:@"黑龙江省哈尔滨市道里区" withToAddress:nil]];
    
    // "当前位置"下面的线
    cell.currentAddressBottomLineLabel.backgroundColor = [UIColor HexStrWithColor:@"d0d0d0"];
    
    // ”订单完成“
    cell.orderTurnoverButton.backgroundColor = [UIColor HexStrWithColor:@"930000"];
    
    // “拨打电话”
    cell.callingButton.backgroundColor = [UIColor HexStrWithColor:@"00DB00"];
    
    cell.lastBottomLineLabel.backgroundColor = [UIColor HexStrWithColor:@"FCFCFC"];
    cell.lastBottomLineLabel.layer.borderWidth = 1;
    cell.lastBottomLineLabel.layer.borderColor = [UIColor HexStrWithColor:@"d0d0d0"].CGColor;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 320;
}



/**
 *  初始化视图
 */
- (void)initWithVeiw{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

/**
 *  自定义cell
 *
 *  @param title     标题
 *  @param starSevel 星级等级
 *
 *  @return 返回整个视图
 */
- (UIView *)fiveCellView:(NSString *)title withStar:(float)starSevel{
    
    UIView *bottomView = [[UIView alloc] init];
    
    // 标题
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 80, 20)];
    titleLabel.text = title;
    titleLabel.textAlignment = 2;
    titleLabel.font = [UIFont systemFontOfSize:15];
    [bottomView addSubview:titleLabel];
    
    // 星
    CWStarRateView *ratingControl = [[CWStarRateView alloc]initWithFrame:CGRectMake(titleLabel.frame.origin.x + titleLabel.frame.size.width + 20, titleLabel.frame.origin.y, 110, 20)];
    [bottomView addSubview:ratingControl];
    ratingControl.scorePercent = starSevel;
    ratingControl.hasAnimation = YES;
    
    return bottomView;
}

/**
 *  自定义cell
 *
 *  @param title     标题
 *  @param content   内容
 *  @param toAddress 目的地址
 *
 *  @return 返回整个视图
 */
- (UIView *)titleAndContent:(NSString *)title andContent:(NSString *)content withToAddress:(NSString *)toAddress{
    UIView *bottomView = [[UIView alloc] init];
    
    // 标题
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 80, 20)];
    titleLabel.text = title;
    titleLabel.textAlignment = 2;
    titleLabel.font = [UIFont systemFontOfSize:15];
    [bottomView addSubview:titleLabel];
    
    // 内容
    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.frame.origin.x + titleLabel.frame.size.width + 20, 10, 200, 20)];
    contentLabel.text = content;
    contentLabel.font = [UIFont systemFontOfSize:15];
    contentLabel.textAlignment = 0;
    //    contentLabel.numberOfLines = 0;
    [contentLabel sizeToFit];
    
    // 根据订单是否被确认设置图片
    if ([contentLabel.text isEqualToString:@"已确认"]) {
        contentLabel.textColor = [UIColor HexStrWithColor:@"8CEA00"];
    } else if ([contentLabel.text isEqualToString:@"未确认"]){
        contentLabel.textColor = [UIColor HexStrWithColor:@"FF2D2D"];
    }
    
    // 如果是“车号：”信息，设置字体颜色
    if ([title isEqualToString:@"车号:"]) {
        titleLabel.textColor = [UIColor HexStrWithColor:@"EA0000"];
        contentLabel.textColor = [UIColor HexStrWithColor:@"EA0000"];
    }
    // 如果标题是“所属公司：”，设置内容的字体颜色
    if ([title isEqualToString:@"所属公司:"]) {
        contentLabel.textColor = [UIColor HexStrWithColor:@"EA0000"];
    }
    
    [bottomView addSubview:contentLabel];
    
    // 如果是地址或者路线信息，设置导航图片
    if ([title isEqualToString:@"地址:"] || [title isEqualToString:@"路线:"]) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(contentLabel.frame.origin.x + contentLabel.frame.size.width + 5, contentLabel.frame.origin.y + 5, 18 / 2.0, 21 / 2.0)];
        imageView.image = [UIImage imageNamed:@"jt_xl"];
        [bottomView addSubview:imageView];
        
        UILabel *toAddLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageView.frame.origin.x + imageView.frame.size.width + 5, contentLabel.frame.origin.y, 200, 20)];
        toAddLabel.text = toAddress;
        [bottomView addSubview:toAddLabel];
    }
    
    return bottomView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
